/*基于JQ的带按钮控制图片左右无间隙滚动插件
 *作者 林吉
 *QQ 317365887
 *邮箱 317365887@qq.com 
*/    
(function($){
	$.fn.movePicX=function(options)
	{
		var opts=$.extend({}, $.fn.movePicX.defaults, options);
		return this.each(function()
		{
      	    var $this=$(this);
			var $scrollObj=$(opts.scrollObj,$this),
			$target=$scrollObj.find(opts.targetObj),
			_targetSize,
			_num,
			_autoPlay,
			_stop = false,
			$preBtn=$(opts.preBtn,$this),
			$nextBtn=$(opts.nextBtn,$this),
			_targetSize=$target.width(),
			_num=$target.length;
			
			$scrollObj.css("width",_num*_targetSize); 	 
			$preBtn.click(function(){
				xToLeft();
			});	
			$nextBtn.click(function(){
				xToRight();
			});
			
			function  xToLeft()
			{
				if(!$scrollObj.is(":animated"))
				{
					$scrollObj.animate({left:"-"+_targetSize},opts.easing,function(){
					$scrollObj.find(opts.targetObj+":first").appendTo($scrollObj);
						$scrollObj.css({"left":"0"});
						if(opts.autoPlay&&!_stop)_autoPlay=setTimeout(xToLeft,opts.timer);
					});
				}	
			}
			
			function xToRight()
			{
				if(!$scrollObj.is(":animated"))
				{
				    $scrollObj.find(opts.targetObj+":last").prependTo($scrollObj);
					$scrollObj.css({"left":-_targetSize});
					$scrollObj.stop().animate({"left":0},opts.easing,function(){
						if(opts.autoPlay&&!_stop)_autoPlay=setTimeout(xToRight,opts.timer);
					});
					
				}
			}
			
			// 如果滑鼠移入 $block 時
			$this.hover(function(){
				_stop = true;
				clearTimeout(_autoPlay);
			}, function(){
				_stop = false;
				_autoPlay = setTimeout(xToRight,opts.timer);
			});
			
			if(opts.autoPlay){_autoPlay = setTimeout(xToRight,opts.timer);}

					
		});
	};
	
	$.fn.movePicX.defaults=
	{
		scrollObj:'.scrollObj',
		targetObj:"li",//被控制添加子对象
		preBtn:'.btnPre',
		nextBtn:'.btnNext',
		autoPlay:true,
		speed:1000,
		timer:3000,
		easing:'easeInOutExpo'
	};
})(jQuery); 